/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package presentation.view;

import businessLogic.facade.AlumnoFacade;
import javax.swing.JOptionPane;
import presentation.controller.ControlPanelMiCuenta;
import vo.AlumnoVO;

/**
 *
 * @author Joanna 8a
 */
public class PanelMiCuenta extends javax.swing.JPanel {

    /**
     * Creates new form PanelMiCuenta
     * @param CamposEditables Cuando entra en las Opciones de ver cuenta o eliminar cuenta es false, si es Modificar es true
     * @param Opcion La opcion de manejo de cuenta: ver, modificar o eliminar.
     */
    public PanelMiCuenta(boolean CamposEditables, String Opcion, FramePrincipal fp) {
        this.parent = fp;
        initComponents();  
        AlumnoVO alumno = new ControlPanelMiCuenta().FindByIp();
        jTextFieldNombreMiCta.setEditable(CamposEditables); 
        jTextFieldNombreMiCta.setText(alumno.getNombre());
        jTextFieldMiCta.setEditable(CamposEditables);
        jTextFieldMiCta.setText(alumno.getApellido());
        jTextFieldCarreraMiCta.setEditable(CamposEditables);
        jTextFieldCarreraMiCta.setText(alumno.getCarrera());
        //setBorder(javax.swing.BorderFactory.createTitledBorder(null, Opcion, javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 1, 14), new java.awt.Color(0, 102, 102)));
        jButtonMiCta.setText(Opcion);
        if (Opcion.equals("Ver Cuenta")){
            jButtonMiCta.setVisible(false);
        }
       
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelNombreMiCta = new javax.swing.JLabel();
        jLabelApellidosMiCta = new javax.swing.JLabel();
        jLabelCarrMiCta = new javax.swing.JLabel();
        jTextFieldNombreMiCta = new javax.swing.JTextField();
        jTextFieldMiCta = new javax.swing.JTextField();
        jTextFieldCarreraMiCta = new javax.swing.JTextField();
        jButtonMiCta = new javax.swing.JButton();
        jButtonVolver = new javax.swing.JButton();

        setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Mi Cuenta", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 1, 14), new java.awt.Color(0, 102, 102))); // NOI18N

        jLabelNombreMiCta.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        jLabelNombreMiCta.setText("Nombre");

        jLabelApellidosMiCta.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        jLabelApellidosMiCta.setText("Apellidos");

        jLabelCarrMiCta.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        jLabelCarrMiCta.setText("Carrera");

        jTextFieldNombreMiCta.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        jTextFieldNombreMiCta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldNombreMiCtaActionPerformed(evt);
            }
        });

        jTextFieldMiCta.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        jTextFieldMiCta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldMiCtaActionPerformed(evt);
            }
        });

        jTextFieldCarreraMiCta.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        jTextFieldCarreraMiCta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldCarreraMiCtaActionPerformed(evt);
            }
        });

        jButtonMiCta.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        jButtonMiCta.setText("Guardar");
        jButtonMiCta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonMiCtaActionPerformed(evt);
            }
        });

        jButtonVolver.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        jButtonVolver.setText("Volver");
        jButtonVolver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVolverActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelNombreMiCta)
                            .addComponent(jLabelApellidosMiCta)
                            .addComponent(jLabelCarrMiCta))
                        .addGap(76, 76, 76)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldNombreMiCta)
                            .addComponent(jTextFieldMiCta)
                            .addComponent(jTextFieldCarreraMiCta, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(81, 81, 81)
                        .addComponent(jButtonMiCta)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonVolver)))
                .addContainerGap(26, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNombreMiCta)
                    .addComponent(jTextFieldNombreMiCta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelApellidosMiCta)
                    .addComponent(jTextFieldMiCta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelCarrMiCta)
                    .addComponent(jTextFieldCarreraMiCta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonMiCta)
                    .addComponent(jButtonVolver))
                .addContainerGap(15, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jTextFieldNombreMiCtaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldNombreMiCtaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldNombreMiCtaActionPerformed

    private void jTextFieldMiCtaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldMiCtaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldMiCtaActionPerformed

    private void jTextFieldCarreraMiCtaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldCarreraMiCtaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldCarreraMiCtaActionPerformed

    private void jButtonVolverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVolverActionPerformed
        parent.cambiarPanel(new PanelPrincipal(parent));
    }//GEN-LAST:event_jButtonVolverActionPerformed

    private void jButtonMiCtaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMiCtaActionPerformed
        eliminarCuenta();
    }//GEN-LAST:event_jButtonMiCtaActionPerformed

    private void eliminarCuenta(){
        vo.AlumnoVO elim = new ControlPanelMiCuenta().FindByIp();
        
        if(new AlumnoFacade().delete(elim.getUsername())){
            JOptionPane.showMessageDialog(this, "El Usuario ha sido eliminado exitosamente!", "Aviso", JOptionPane.INFORMATION_MESSAGE);
            parent.cambiarPanel(new PanelLogin(parent));
            parent.controlBarraHerramientas(false);
        }
        else{
            JOptionPane.showMessageDialog(this, "No se ha podido eliminar el Usuario.\n "
                                                + "Por favor intente mas tarde", "Error", JOptionPane.INFORMATION_MESSAGE);
            parent.cambiarPanel(new PanelPrincipal(parent));
        }
    }
    
    private FramePrincipal parent;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonMiCta;
    private javax.swing.JButton jButtonVolver;
    private javax.swing.JLabel jLabelApellidosMiCta;
    private javax.swing.JLabel jLabelCarrMiCta;
    private javax.swing.JLabel jLabelNombreMiCta;
    private javax.swing.JTextField jTextFieldCarreraMiCta;
    private javax.swing.JTextField jTextFieldMiCta;
    private javax.swing.JTextField jTextFieldNombreMiCta;
    // End of variables declaration//GEN-END:variables
}
